/**
 * 主题侧边栏样式
 * 提供隐藏/显示右侧边栏的视觉效果
 */

/* 侧边栏隐藏状态 */
.theme-sidebar-hidden {
    display: none !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
}

/* 主内容区域全宽状态 - 使用更高特异性选择器 */
body .layout-main,
html body .layout-main,
body .theme-full-width,
html body .theme-full-width {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 100% !important;
}

/* 主内容区域包装器全宽状态 */
body .layout-main-section-wrapper,
html body .layout-main-section-wrapper,
body .theme-full-width + .layout-main-section-wrapper,
html body .theme-full-width ~ .layout-main-section-wrapper,
body .theme-full-width ~ .layout-main-section-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 100% !important;
}

/* 强制重置布局 - 使用最高特异性选择器 */
body html .layout-main,
body html .layout-main-section-wrapper,
body html .theme-full-width,
body html .theme-full-width ~ .layout-main-section-wrapper,
body html .theme-full-width + .layout-main-section-wrapper {
    display: block;
    position: relative;
    overflow: visible;
    float: none;
    clear: none;
}

/* 简化侧边栏正常显示时的宽度控制 */
.layout-side-section:not(.theme-sidebar-hidden) {
    width: auto;
    display: block;
}

/* 基础重置 */
* {
    box-sizing: border-box;
}

/* 侧边栏切换按钮样式 */
.theme-sidebar-toggle {
    background-color: var(--primary-color, #007AFF) !important;
    color: white !important;
    border: 1px solid var(--primary-color, #007AFF) !important;
    border-radius: 4px !important;
    padding: 4px 8px !important;
    font-size: 12px !important;
    transition: all 0.3s ease !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 32px !important;
    height: 28px !important;
}

.theme-sidebar-toggle:hover {
    background-color: var(--primary-500, #0051D5) !important;
    border-color: var(--primary-500, #0051D5) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 2px 4px rgba(0, 122, 255, 0.2) !important;
}

.theme-sidebar-toggle:active {
    transform: translateY(0) !important;
    box-shadow: 0 1px 2px rgba(0, 122, 255, 0.2) !important;
}

.theme-sidebar-toggle i {
    font-size: 12px !important;
    line-height: 1 !important;
}

/* 移除动画延迟 - 直接显示/隐藏 */
.layout-side-section {
    transition: none !important;
}

.layout-main {
    transition: none !important;
}

/* 右侧边栏隐藏时的布局调整 */
.layout-two-column .layout-side-section.right.theme-sidebar-hidden ~ .layout-main-section-wrapper {
    margin-right: 0 !important;
}

.layout-two-column .layout-side-section.theme-sidebar-hidden {
    margin-right: 0 !important;
}

/* 左侧边栏隐藏时的布局调整 */
.layout-two-column .layout-side-section.left.theme-sidebar-hidden ~ .layout-main-section-wrapper {
    margin-left: 0 !important;
}

.layout-two-column .layout-side-section.theme-sidebar-hidden {
    margin-left: 0 !important;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .layout-side-section {
        position: fixed !important;
        top: var(--navbar-height, 60px) !important;
        right: 0 !important;
        height: calc(100vh - var(--navbar-height, 60px)) !important;
        z-index: 999 !important;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1) !important;
        background: white !important;
    }
    
    .theme-sidebar-hidden {
        transform: translateX(100%) !important;
        transition: transform 0.3s ease-in-out !important;
    }
    
    .layout-main-section-wrapper {
        margin-right: 0 !important;
        width: 100% !important;
    }
}

/* 平板设备适配 */
@media (min-width: 769px) and (max-width: 1024px) {
    .layout-side-section {
        width: 200px !important;
        min-width: 200px !important;
    }
    
    .theme-sidebar-hidden ~ .layout-main-section-wrapper {
        width: calc(100% - 20px) !important;
        margin-left: 10px !important;
        margin-right: 10px !important;
    }
}

/* 深色主题支持 */
@media (prefers-color-scheme: dark) {
    .theme-sidebar-toggle {
        background-color: var(--primary-600, #0051D5) !important;
        border-color: var(--primary-600, #0051D5) !important;
        color: white !important;
    }
    
    .theme-sidebar-toggle:hover {
        background-color: var(--primary-700, #0041B3) !important;
        border-color: var(--primary-700, #0041B3) !important;
    }
}

/* 无障碍支持 */
.theme-sidebar-toggle:focus {
    outline: 2px solid var(--primary-color, #007AFF) !important;
    outline-offset: 2px !important;
}

.theme-sidebar-toggle[aria-pressed="true"] {
    background-color: var(--primary-700, #0051D5) !important;
}

/* 加载状态 */
.theme-sidebar-toggle.loading {
    opacity: 0.6 !important;
    cursor: not-allowed !important;
}

.theme-sidebar-toggle.loading::after {
    content: '' !important;
    position: absolute !important;
    width: 12px !important;
    height: 12px !important;
    border: 1px solid transparent !important;
    border-top-color: white !important;
    border-radius: 50% !important;
    animation: spin 1s linear infinite !important;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 动画性能优化 */
.layout-side-section,
.layout-main {
    will-change: width, margin, transform, opacity;
}

/* 防止布局抖动 */
.layout-side-section.theme-sidebar-hidden {
    overflow: hidden !important;
    max-height: 0 !important;
}

/* 自定义滚动条 */
.theme-sidebar-hidden ~ .layout-main-section-wrapper {
    overflow-x: hidden !important;
}